//
//  THReportView.m
//  YJB
//
//  Created by 中电大维 on 2017/2/13.
//  Copyright © 2017年 YJB. All rights reserved.
//

#import "THReportView.h"

@interface THReportView ()

@property (nonatomic, strong)UIButton *button;

@end

@implementation THReportView

- (instancetype)init
{
    if (self = [super initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)]) {
        [self addSubview:self.button];
        [self addTapGestureRecognizer];
        self.button.center = self.center;
        self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.3];
    }
    return self;
}

- (void)setTitlename:(NSString *)titlename
{
    [self.button setTitle:titlename forState:UIControlStateNormal];
}

- (void)reportClick:(UIButton *)button
{
    [self setHidden:YES];
    if ([self.delegate respondsToSelector:@selector(pushReportController)]) {
        [self.delegate pushReportController];
    }
}

- (void)tapGestureRecognizerClick:(UITapGestureRecognizer *)recognizer
{
    [self setHidden:YES];
}

- (void)addTapGestureRecognizer
{
    UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGestureRecognizerClick:)];
    recognizer.numberOfTapsRequired = 1; // 单击
    [self addGestureRecognizer:recognizer];
}


- (UIButton *)button
{
    if (!_button) {
        _button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width-60, 44)];
        _button.backgroundColor = [UIColor whiteColor];
        [_button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        _button.titleLabel.font = [UIFont systemFontOfSize:16];
        [_button addTarget:self action:@selector(reportClick:) forControlEvents:UIControlEventTouchUpInside];
        [_button.layer setMasksToBounds:YES];
        [_button.layer setCornerRadius:3.0];
    }
    return _button;
}

@end
